import torch
from torch import nn


def get_sparse_eye(num):
    location = torch.LongTensor([[k for k in range(0, num)], [j for j in range(0, num)]])
    value = torch.FloatTensor([1] * num)
    return torch.sparse.FloatTensor(location, value)


def initNetParams(net):
    for m in net.modules():
        if isinstance(m, nn.Linear):
            nn.init.kaiming_uniform_(m.weight)
            nn.init.constant_(m.bias, 0)
        elif isinstance(m, nn.Embedding):
            m.weight.data.normal_(0, 0.01)
